package sample.plugin.language.python.decision;

import com.rapid.api.lang.engine.highlight.decision.DecisionResult;
import com.rapid.api.lang.engine.highlight.token.TokenModel;

import io.github.rosemoe.sora.widget.schemes.EditorColorScheme;
import sample.plugin.language.python.PythonState;
import sample.plugin.language.python.PythonToken;

public class PythonIdentifierDecision extends PythonDecision {
    @Override
    public Iterable<DecisionResult> decide(TokenModel model, PythonState state) {
        if (model.token == PythonToken.IDENTIFIER) {
            TokenModel next = getNextNonEmptyToken(model);
            if (next != null) {
                if (next.token == PythonToken.LPAREN) {
                    return singleColor(EditorColorScheme.FUNCTION);
                } else if (next.token == PythonToken.DOT || next.token == PythonToken.EQ) {
                    return singleColor(EditorColorScheme.FIELD);
                }
            }
            TokenModel prev = getPrevNonEmptyToken(model);
            if (prev != null) {
                if (prev.token == PythonToken.CLASS) {
                    return singleColor(EditorColorScheme.CLASS);
                } else if (prev.token == PythonToken.DOT
                        || prev.token == PythonToken.LPAREN
                        || prev.token == PythonToken.COMMA) {
                    return singleColor(EditorColorScheme.FIELD);
                }
            }
            if (model.text.startsWith("__") && model.text.endsWith("__")) {
                DecisionResult.StyleContent content = new DecisionResult.StyleContent();
                content.foregroundId = EditorColorScheme.FIELD;
                content.bold = true;
                content.italic = true;
                DecisionResult result = new DecisionResult();
                result.kind = DecisionResult.ResultKind.ACCEPT;
                result.content = content;
                return single(result);
            }
        }
        return refuse();
    }
}
